using System;
using System.Data;
using System.Data.SqlClient;

namespace TypingMonkey
{
	/// <summary>
	/// 
	/// </summary>
	public class DataManager
	{
		private static string _ConnectionString = "";

		private static void Init()
		{
			_ConnectionString = "Server=DNEPR\\SQL2000; Database=Monkey; User ID=sa; Password=sqlserver;Trusted_Connection=False";
		}

		public static void Execute (string query)
		{
			Init();
			SqlCommand exCommand = new SqlCommand(query,new SqlConnection(_ConnectionString));
			exCommand.Connection.Open();
			exCommand.ExecuteNonQuery();
			exCommand.Connection.Close();
		}

		public static void ExecuteSP (string spname)
		{
			Init();
			SqlCommand exCommand = new SqlCommand(spname,new SqlConnection(_ConnectionString));
			exCommand.CommandType = CommandType.StoredProcedure;
			exCommand.Connection.Open();
			exCommand.ExecuteNonQuery();
			exCommand.Connection.Close();
		}

		public static void ExecuteCmd (SqlCommand exCommand)
		{
			Init();
			exCommand.Connection = new SqlConnection(_ConnectionString);
			exCommand.Connection.Open();
			exCommand.ExecuteNonQuery();
			exCommand.Connection.Close();
		}

		public static DataTable ExecuteDataTable (string query)
		{
			Init();
			SqlConnection conn = new SqlConnection(_ConnectionString);
			SqlCommand exCommand = new SqlCommand(query,conn);
			SqlDataAdapter dsc = new SqlDataAdapter(exCommand);
			DataTable dt = new DataTable();
			dsc.Fill(dt);
			return dt;
		}

		public static DataTable ExecuteSPDataTable (string spname)
		{
			Init();
			SqlCommand comm = new SqlCommand(spname,new SqlConnection(_ConnectionString));
			comm.CommandType = CommandType.StoredProcedure;
			SqlDataAdapter dsc = new SqlDataAdapter(comm);
			DataTable dt = new DataTable();
			dsc.Fill(dt);
			return dt;
		}

		public static DataTable ExecuteCmdDataTable (SqlCommand cmd)
		{
			Init();
			cmd.Connection = new SqlConnection(_ConnectionString);
			SqlDataAdapter dsc = new SqlDataAdapter(cmd);
			DataTable dt = new DataTable();
			dsc.Fill(dt);
			return dt;
		}
	}
}
